package com.example.springboot.mqtt.controller;

import com.baidu.aip.ocr.AipOcr;
import com.example.springboot.mqtt.config.AipocrConfig;
import com.example.springboot.mqtt.serivice.ILotteryService;
import org.json.JSONObject;
import org.json.JSONString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@RestController
@RequestMapping("/aipocr")
public class AipOcrController {

    @Autowired
    private AipocrConfig aipOcrConfig;
    @Autowired
    private ILotteryService lotteryService;

    @GetMapping("/general_basic")
    public String generalBasic(){
        AipOcr client = new AipOcr(aipOcrConfig.getAppId(), aipOcrConfig.getApiKey(), aipOcrConfig.getSecretKey());
        try{
            // 传入可选参数调用接口
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("language_type", "CHN_ENG");
            options.put("detect_direction", "true");
            options.put("detect_language", "true");
            options.put("probability", "true");

            // 参数为本地图片路径
            String image = "src/main/resources/lottery/123.jpg";
            JSONObject res = client.basicAccurateGeneral(image, options);

//            lotteryService.getLottery(res.toString());
//            String text = "中国福利彩票CHINA WELFARE LOTTERY玩法：双色球-单式35020162EA35-82B4-00ED-0E8E-B36D/44711214/4099DA.031113142933-04(1)B.010911132231-10(1)C.010209242532-06(1)D.212224282932-14(1)E.011017212932-10开奖期：202209322-08-14合计10元销售期：2022093-11422-08-1217:50:07厦门同安区同安南门路140号奖池余额：1927997908.00元上期开奖号码：21-20-07-27-10-16+11感谢您为公益慈善事业贡献3.60元福建省福利彩票发行中心承销";
            lotteryService.getLotteryRegex(res.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
